package leetcode.stack;

import utils.node.ListNode;

/**
 * @Description: https://leetcode.cn/problems/min-stack/
 * @Author Ammar
 * @Create 2023/7/11 14:38
 */
public class _155_最小栈_双栈 {
    ListNode head = null;
    public _155_最小栈_双栈() {
        head = new ListNode(0, Integer.MAX_VALUE, null);
    }

    public void push(int val) {
        head = new ListNode(val, Math.min(head.min, val), head);
    }

    public void pop() {
        head = head.next;
    }

    public int top() {
        return head.val;
    }

    public int getMin() {
        return head.min;
    }

    private static class ListNode {
        Integer val;
        Integer min;
        ListNode next;

        public ListNode(Integer val, Integer min, ListNode next) {
            this.val = val;
            this.min = min;
            this.next = next;
        }
    }
}
